<?php
include 'connect.php';

$activity =$_POST['activity'];
$date =$_POST['deadline'];
$type =$_POST['type'];

$query = "INSERT INTO list (activity, deadline, type)
VALUES ('$activity','$date','$type')";

if (!mysql_query($query,$con))
  {
  die('error: ' . mysql_error());
  }
echo "Schedule(s) Updated \n";

$sql="SELECT * FROM list";
function drawtable($sql, $fieldarray){
//count number of columns
 $columns = count($fieldarray);
//run the query
 $result = mysql_query($sql) or die(mysql_error()) ;
 $itemnum = mysql_num_rows($result);
 $items = mysql_fetch_assoc($result);
 if($itemnum > 0){
  do{  
   echo "<tr>" ;
   for($x = 0; $x < $columns; $x++){
    echo "<td>" .$items[$fieldarray[$x]]. "</td>" ;
   }
   echo "</tr>" ;
  }while($items = mysql_fetch_assoc($result));
 }
}
?>

<html>
<head>
	<title>Things to Do</title>
		<link href="css/bootstrap.css" rel="stylesheet">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<link href="css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
<table class="table table-striped">
<?php
$fieldarray = array("activity","deadline","type");
drawtable("SELECT * FROM list", $fieldarray);
?>
</table>

<ul class="nav nav-pills">
  <li class="disabled"><a href="awal.html">Home</a></li>
</ul>
</body>
</html>